#!/bin/bash
# ----------------------------------------------------------------
#   1-CreateDirecotryStructure.sh: Create the directory structure
#   	and relocate each files to the right place
#
#	Usage:
#		1-CreateDirectoryStructure.sh rawDataSrc projectDir subjID
#   initializes the Adaptation fMRI experiment. This experiment 
#   effect of stimulus history on the current evoked response,
#   on serial position -1 to -N are manipulated in a 
#
#
#   Inputs
#   -------
#   [protocolListFileName]: path to a file that should contain a
#   	description of the protocols to be used. If nothing is
#   	the file ./Config/ProtocolList.cfg will be used
#
#
#   Outputs
#   -------
#   ./Data/[expType]/[protocol]/[subjID]/[subjID]-[protocol]-
#  	this file will store all experimental info, experiment
#   	parameters, stimuli used, and data collected
#
#   Examples
#   -------
#    i) AdaptID_v1_1('./protocols.txt')
#   ii) AdaptID_v1_1
#
# ----------------------------------------------------------------
# ``Redistribution and use, with or without modification, are
#	permitted provided that the list of contributors below is
#	preserved.``
#
#   Original code by Marcelo G Mattar (09/04/2012)
#	mattar@sas.upenn.edu
# ----------------------------------------------------------------


# --- Check input command ---
if [ $# -ne 1 ]; then
cat << EOF
USAGE: `basename $0` subjectID
EOF
	exit 1
fi

# --- Read input parameters ---
subjectID=$1

# --- MAIN PARAMETERS ---
projectDir='/jet/mattar/AdaptID'
rawDataSrc='/jet/mattar/AdaptID/Data/'$subjectID
directoryStructureFile='/jet/mattar/AdaptID/Scripts/directoryStructure'

dataDir=$projectDir/Data
analysesDir=$projectDir/Analyses
anatomyDir=$dataDir/$subjectID/Anatomy
B0mapDir=$dataDir/$subjectID/B0map


# --- Save calling directory ---
OCD=$PWD

# --- Set full permissions to all files in the directory
chmod 777 *


# -----------------------------------------------------
# 1) --- CREATE DIRECTORY STRUCTURE ---
# -----------------------------------------------------

#./1-CreateDirectoryStructure $rawDataSrc $projectDir $subjectID


# -----------------------------------------------------
#####--> Check names of each scan
#####--> Make sure indices are correct
# -----------------------------------------------------
# 2) --- MAKE NIFTIS AND MOVE FILES AROUND ---
# -----------------------------------------------------

#./2-MakeNiftisAndMoveFilesAround $dataDir/$subjectID $directoryStructureFile


# -----------------------------------------------------
#####--> Delete localizer .nii.gz files
# -----------------------------------------------------
# 3) --- CREATE B0 FIELD MAP ---
# -----------------------------------------------------

#./3-B0_PrepareFieldmap $B0mapDir/B0phase.nii.gz $B0mapDir/B0phase2.nii.gz $B0mapDir/B0mag.nii.gz


# -----------------------------------------------------
# 4) --- RUN BRAIN EXTRACTION TOOL ---
# -----------------------------------------------------

#./4-RunBET $anatomyDir


# -----------------------------------------------------
#####--> Pick the best threshold level and change the FEAT script if not 0.4
# -----------------------------------------------------
# 5) --- RUN FEAT ON FOBS LOCALIZER ---
# -----------------------------------------------------

./5-RunFEAT_FOBSLoc $dataDir $analysesDir $subjectID $directoryStructureFile


# -----------------------------------------------------
# 6) --- RUN FEAT ON MAIN EXPERIMENTAL DATA ---
# -----------------------------------------------------

./6-RunFEAT_MainExp $dataDir $analysesDir $subjectID $directoryStructureFile


# -----------------------------------------------------
# 7) --- RUN 2nd LEVEL FEAT ---
# -----------------------------------------------------

#./7-RunFEAT_2ndLevel $dataDir $analysesDir $subjectID Color
#./7-RunFEAT_2ndLevel $dataDir $analysesDir $subjectID Face





cd $OCD

exit 0